package com.internetCafes.spms.web.tenant.service.impl;

import com.internetCafes.spms.core.generic.GenericDao;
import com.internetCafes.spms.core.generic.GenericServiceImpl;
import com.internetCafes.spms.core.model.pageModel.DataGrid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.internetCafes.spms.web.tenant.dao.TenantCertiInfoMapper;
import com.internetCafes.spms.web.tenant.model.TenantCertiInfo;
import com.internetCafes.spms.web.tenant.service.TenantCertiInfoService;


/**
 * 租户企业资质 TenantCertiInfoService 实现类
 *
 * @author Sunny
 * @email rekeeper2011@hotmail.com
 * @date 2019-10-31 18:09:54
 */
@Service("tenantCertiInfoService")
public class TenantCertiInfoServiceImpl extends GenericServiceImpl<TenantCertiInfo, Long> implements TenantCertiInfoService {

    @Autowired
    private TenantCertiInfoMapper tenantCertiInfoMapper;

    @Override
    public List<TenantCertiInfo> query(Map<String, Object> params) {
        return tenantCertiInfoMapper.selectByParams(params);
    }

    @Override
    public TenantCertiInfo findById(Long id) {
        return tenantCertiInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<TenantCertiInfo> queryByIds(List<Long> ids) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("ids", ids);
        return tenantCertiInfoMapper.selectByParams(params);
    }

    @Override
    public List<TenantCertiInfo> page(Map<String, Object> params, int page, int rows) {
        params.put("page", page);
        params.put("rows", rows);
        return tenantCertiInfoMapper.selectByParams(params);
    }

    @Override
    public long count(Map<String, Object> params) {
        return tenantCertiInfoMapper.countByParams(params);
    }

    @Override
    public TenantCertiInfo findFirst(Map<String, Object> params) {
        List<TenantCertiInfo> list = tenantCertiInfoMapper.selectByParams(params);
        TenantCertiInfo tenantCertiInfo =null;
        if (list != null && list.size() > 0) {
            tenantCertiInfo =list.get(0);
        }
        return tenantCertiInfo;
    }

    @Override
    public int save(TenantCertiInfo tenantCertiInfo) {
        return tenantCertiInfoMapper.insert(tenantCertiInfo);
    }

    @Override
    public int saveBatch(List<TenantCertiInfo> tenantCertiInfoList) {
        return tenantCertiInfoMapper.insertBatch(tenantCertiInfoList);
    }

    @Override
    public int saveSelective(TenantCertiInfo tenantCertiInfo) {
        return tenantCertiInfoMapper.insertSelective(tenantCertiInfo);
    }

    @Override
    public int update(TenantCertiInfo tenantCertiInfo) {
        return tenantCertiInfoMapper.updateByPrimaryKey(tenantCertiInfo);
    }

    @Override
    public int updateSelective(TenantCertiInfo tenantCertiInfo) {
        return tenantCertiInfoMapper.updateByPrimaryKeySelective(tenantCertiInfo);
    }

    @Override
    public int delete(Long id) {
        return tenantCertiInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteBatch(List<Long> ids) {
        return tenantCertiInfoMapper.deleteBatchByPrimaryKey(ids);
    }

    @Override
    public void deleteBatch(Long[] ids) {
        if(ids != null && ids.length > 0){
            for(Long id : ids){
                delete(id);
            }
        }
    }

    @Override
    public GenericDao<TenantCertiInfo, Long> getDao() {
        return tenantCertiInfoMapper;
    }

    /**
	 * DataGrid
	 */
    @Override
    public DataGrid dataGrid(Map<String, Object> params, int pageNo, int pageSize) {

        List<TenantCertiInfo> tenantCertiInfoList = page(params, (pageNo - 1 < 0 ? -1 : pageNo - 1) * pageSize, pageSize);
        long count = count(params);

        return new DataGrid(tenantCertiInfoList, count, pageSize, pageNo);
    }

    @Override
    public void deleteByResourceAndTenantId(Map<String, Object> params) {
        tenantCertiInfoMapper.deleteByResourceAndTenantId(params);
    }
}